package com.sn.shop.model;

import java.util.ArrayList;
import java.util.List;

/**
 * @author sn
 * @date 2018/7/27
 * @description 分类树
 */
public class CategoryTree {

    private List<Category> node;

    public void categoryList(List<Category> data) {
        node = categoryChild(0, data);
    }

    private List<Category> categoryChild(int id, List<Category> data) {
        List<Category> result = new ArrayList<>();
        for (Category category : data) {
            if(category.getPid() == id) {
                category.setChildren(categoryChild(category.getId(), data));
                result.add(category);
            }
        }
        return result;
    }

    public List<Category> getNode() {
        return node;
    }

    public void setNode(List<Category> node) {
        this.node = node;
    }
}
